package leetcode.easy.q104;

import leetcode.util.TreeNode;
import leetcode.util.Utils;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Q {
    public static void main(String[] args) {
        log.info("max deep:{}", new Solution().maxDepth(Utils.buildTree(3, 9, 20, null, null, 15, 7)));
    }
}

class Solution {
    public int maxDepth(TreeNode root) {
        return findMaxDeep(root, 0);
    }

    private int findMaxDeep(TreeNode node, int parentDeep) {
        if (node == null) {
            return parentDeep;
        } else {
            return Math.max(findMaxDeep(node.left, parentDeep + 1), findMaxDeep(node.right, parentDeep + 1));
        }
    }
}